#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Zhangcl
from modules.connect_db import engine, UserProfile, RemoteUser, Host, Group, BindHost, AuditLog, Admin_user
from sqlalchemy.orm import sessionmaker
session_connet = sessionmaker(bind=engine)
session = session_connet()


class User_login(object):
    def __init__(self, login_user, login_passwd, user_type):
        self.login_user = login_user
        self.login_passwd = login_passwd
        self.user_type = user_type

    def type_choise(self):
        if self.user_type == 'users':
            obj = session.query(UserProfile).filter(UserProfile.username == self.login_user).first()
            run = 'users'
        if self.user_type == 'admin':
            obj = session.query(Admin_user).filter(Admin_user.admin_name == self.login_user).first()
            run = 'admin'
        if obj is None:
            print('用户不存在！')
        else:
            if obj.password == self.login_passwd:
                return run
            else:
                print('密码错误！')
                return False
